package cn.gzsxt.music.mapper;

import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.text.StrBuilder;
import org.apache.ibatis.annotations.Mapper;

import cn.gzsxt.music.query.SingerQueryObject;

@Mapper
public class SingerProvider {
	public String checkExistsSingerActionName(Map<String, Object> params) {
		StringBuilder sql = new StringBuilder();
		sql.append( "select * from mc_singer where singer_name = #{singer_name}");	
		
		//如果有singer_id就拼接singer_id对应的sql语句
		if(StringUtils.isNotBlank((String)params.get("singer_id"))) {
			sql.append(" and singer_id !=#{singer_id}");
		}
		
		return sql.toString();	
	}
	
	//查总数
	public String selectSingerTotalByQo(SingerQueryObject qo) {		
		StrBuilder sql = new StrBuilder();
		sql.append("select count(*) from mc_singer");
		if (StringUtils.isNotBlank(qo.getKeyword())) {
			sql.append(" where singer_name like \"%\"#{keyword}\"%\"");
		}
		
		return sql.toString();
			
	}
	
	//查结果
	public String selectSingerListByQo(SingerQueryObject qo) {
		StrBuilder sql = new StrBuilder();
		sql.append("select * from mc_singer");
		if (StringUtils.isNotBlank(qo.getKeyword())) {
			sql.append(" where singer_name like \"%\"#{keyword}\"%\"");
		}
		sql.append(" limit #{beginIndex},#{rows}");
		return sql.toString();		
		
	}
	
	
	
	
}
